home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
Other Langs
/
Tickle-4.0 (tcl)
/
src
/
floppycopy.c
< prev
next >
Wrap
Text File
|
1993-11-18
|
30KB
|
1,074 lines
/*
** This source code was written by Tim Endres
** Email: time@ice.com.
** USMail: 8840 Main Street, Whitmore Lake, MI 48189
**
** Some portions of this application utilize sources
** that are copyrighted by ICE Engineering, Inc., and
** ICE Engineering retains all rights to those sources.
**
** Neither ICE Engineering, Inc., nor Tim Endres,
** warrants this source code for any reason, and neither
** party assumes any responsbility for the use of these
** sources, libraries, or applications. The user of these
** sources and binaries assumes all responsbilities for
** any resulting consequences.
*/
#ifdef MPW3
# pragma segment FloppyCopy
#endif
#include "tickle.h"
#include "tge.h"
#include <DiskInit.h>
#include <OSEvents.h>
extern int errno;
#define MAX_DIR_STK 32
#define POP_DIR() ( dir_stk[--dir_stk_ptr] )
#define POP_INFO() ( dir_info_stk[--dir_info_stk_ptr] )
#define CURRENT_DIR() ( (dir_stk_ptr > 0) ? dir_stk[dir_stk_ptr - 1] : 2 )
#define PUSH_DIR(DIR) ( dir_stk[dir_stk_ptr++] = (DIR) )
#define PUSH_DIR_INFO(INFO) ( dir_info_stk[dir_info_stk_ptr++] = (INFO) )
int curr_drive_number = 1;
int to_vref;
long to_dirid;
int vref_to_unmount = 0;
int file_count_count = 0;
long *dir_stk;
int dir_stk_ptr = 0;
CInfoPBRec *dir_info_stk;
int dir_info_stk_ptr = 0;
int total_count = 0;
int current_count = 0;
int vol_count = 1;
char vol_prefix[32];
char vol_genname[32];
copy_to_floppies()
{
short from_vref, floppy_vref;
long from_dirid;
char from_path[256];
int result;
ParamBlockRec vpb;
CInfoPBRec cpb;
extern void SProgressCopyFiles();
extern void SProgressCounting();
dir_stk = (long *) NewPtr(MAX_DIR_STK * sizeof(long));
dir_info_stk = (CInfoPBRec *) NewPtr(MAX_DIR_STK * sizeof(CInfoPBRec));
if (dir_stk == (long *)0 || dir_info_stk == (CInfoPBRec *)0) {
if (dir_stk != (long *)0)
DisposPtr((Ptr) dir_stk);
if (dir_info_stk != (CInfoPBRec *)0)
DisposPtr((Ptr) dir_info_stk);
message_alert("Not enough memory to save the directory information.");
return;
}
dir_stk_ptr = 0;
dir_info_stk_ptr = 0;
vol_count = 1;
yield_menus(YIELD_ON);
if (! GetFolderPathName("Direcory To Copy...", from_path, &from_vref, &from_dirid))
{
yield_menus(YIELD_OFF);
DisposPtr((Ptr) dir_stk);
DisposPtr((Ptr) dir_info_stk);
return;
}
/* Feedback("We're copying WDRef %d Path '%s'\n", from_vref, from_path); */
cpb.hFileInfo.ioCompletion = 0; /* Synchronous */
cpb.hFileInfo.ioNamePtr = vol_prefix; vol_prefix[0] = 0;
cpb.hFileInfo.ioVRefNum = from_vref; /* Returned here */
cpb.hFileInfo.ioFDirIndex = -1; /* Get the directory in ioDirID */
cpb.hFileInfo.ioDirID = from_dirid; /* same offset as ioFlNum */
result = PBGetCatInfo(&cpb, (Boolean)0); /* Synchronous */
if (result == noErr)
p2cstr(vol_prefix);
else
strcpy(vol_prefix, "Untitled");
if (! GetInputLine("Volume Names Prefix: (Max 20 chars)", vol_prefix))
{
yield_menus(YIELD_OFF);
DisposPtr((Ptr) dir_stk);
DisposPtr((Ptr) dir_info_stk);
return;
}
file_count_count = 0;
StartProgressWindow("\pCount Files", 0, -1, 0, SProgressCounting);
total_count = file_count(from_vref, from_dirid);
StopProgressWindow();
if (total_count == CANCEL) {
Feedback("Copy canceled by user.");
yield_menus(YIELD_OFF);
DisposPtr((Ptr) dir_stk);
DisposPtr((Ptr) dir_info_stk);
return;
}
if (total_count == FAILURE) {
Feedback("Error counting the files to be copied.");
yield_menus(YIELD_OFF);
DisposPtr((Ptr) dir_stk);
DisposPtr((Ptr) dir_info_stk);
return;
}
current_count = 0;
Feedback("Total files and folders to copy = %d.", total_count);
/* Feedback("VOL Prfix <%s> ", vol_prefix); */
StartProgressWindow("\pCopy Files", 0, total_count, 0, SProgressCopyFiles);
vpb.volumeParam.ioCompletion = (ProcPtr)0;
vpb.volumeParam.ioNamePtr = NULL;
vpb.volumeParam.ioVRefNum = 1; /* drive number... */
PBUnmountVol(&vpb);
vpb.volumeParam.ioCompletion = (ProcPtr)0;
vpb.volumeParam.ioNamePtr = NULL;
vpb.volumeParam.ioVRefNum = 2; /* drive number... */
PBUnmountVol(&vpb);
SFEject(1);
SFEject(2);
if (! GetFloppy(&floppy_vref))
{
StopProgressWindow();
yield_menus(YIELD_OFF);
DisposPtr((Ptr) dir_stk);
DisposPtr((Ptr) dir_info_stk);
return;
}
to_vref = floppy_vref;
vref_to_unmount = to_vref;
to_dirid = 2;
result = do_floppy_copy(from_path, ":", from_vref, from_dirid);
StopProgressWindow();
SysBeep(0);
if (result == SUCCESS)
Feedback("Copy of '%s:' completed.", from_path);
else if (result == CANCEL)
Feedback("Copy of '%s:' canceled by user.", from_path);
else
message_alert("Copy of '%s' failed.", from_path);
if (in_back_ground)
{
notify_SICN(NOTIFY_COPY_COMPLETE);
}
yield_menus(YIELD_OFF);
DisposPtr((Ptr) dir_stk);
DisposPtr((Ptr) dir_info_stk);
InitCursor();
}
GetFloppy(floppy_vref)
short *floppy_vref;
{
int myerr, result = 0;
char volname[32];
char prompt[128];
ParamBlockRec pb;
ParamBlockRec vpb;
HParamBlockRec hpb;
DialogPtr mydialog;
notify_SICN(NOTIFY_NEED_DISK);
get_another:
if (vref_to_unmount != 0) {
vpb.volumeParam.ioCompletion = (ProcPtr)0;
vpb.volumeParam.ioNamePtr = NULL;
vpb.volumeParam.ioVRefNum = vref_to_unmount;
PBUnmountVol(&vpb);
vref_to_unmount = 0;
}
SFEject(curr_drive_number);
DoYield();
DoYield();
sprintf(prompt, "Insert a floppy for '%.20s #%d'.", vol_prefix, vol_count);
if (! SFGetFloppy(prompt)) {
clear_notify_q(NOTIFY_NEED_DISK);
return 0;
}
DoYield();
DoYield();
pb.volumeParam.ioCompletion = (ProcPtr)0;
pb.volumeParam.ioNamePtr = NULL;
pb.volumeParam.ioVRefNum = curr_drive_number; /* Drive number influence! */
myerr = PBMountVol(&pb);
/* Feedback("PBMountVol(#1)=%d", myerr); */
if (myerr != noErr)
{
if (! AskYesNo("Floppy unreadable. Initialize?", 0))
goto get_another;
mydialog = GetNewDialog(4010, NULL, (WindowPtr)-1);
if (mydialog != NULL) {
SetPort(mydialog);
DrawDialog(mydialog);
}
myerr = DIFormat(curr_drive_number);
if (myerr == noErr) {
if (mydialog != NULL)
DisposDialog(mydialog);
mydialog = GetNewDialog(4009, NULL, (WindowPtr)-1);
if (mydialog != NULL) {
SetPort(mydialog);
DrawDialog(mydialog);
}
myerr = DIVerify(curr_drive_number);
if (myerr == noErr) {
if (mydialog != NULL)
DisposDialog(mydialog);
mydialog = GetNewDialog(4008, NULL, (WindowPtr)-1);
if (mydialog != NULL) {
SetPort(mydialog);
DrawDialog(mydialog);
}
sprintf(vol_genname, "%.20s #%d", vol_prefix, vol_count);
c2pstr(vol_genname);
myerr = DIZero(curr_drive_number, vol_genname);
if (myerr != noErr)
message_alert("Error #%d creating floppy directory.", myerr);
}
else
message_alert("Error #%d verifying floppy format.", myerr);
}
else
message_alert("Error #%d formatting floppy.", myerr);
if (mydialog != NULL)
DisposDialog(mydialog);
if (myerr != noErr)
goto get_another;
}
else {
vref_to_unmount = pb.volumeParam.ioVRefNum;
}
if (myerr == noErr) {
hpb.volumeParam.ioCompletion = 0;
hpb.volumeParam.ioNamePtr = volname;
hpb.volumeParam.ioVRefNum = pb.volumeParam.ioVRefNum;
hpb.volumeParam.ioVolIndex = 0;
myerr = PBHGetVInfo(&hpb, FALSE);
if (myerr != noErr) {
message_alert("Error #%d obtaining volume info (floppy).", myerr);
goto get_another;
}
else if ((hpb.volumeParam.ioVAtrb & 0x8080) != 0) {
message_alert("This floppy is locked.");
vref_to_unmount = hpb.volumeParam.ioVRefNum;
goto get_another;
}
else {
*floppy_vref = hpb.volumeParam.ioVRefNum;
vref_to_unmount = hpb.volumeParam.ioVRefNum;
if (hpb.volumeParam.ioVFilCnt > 1 || hpb.volumeParam.ioVDirCnt > 1) {
if (! AskYesNo("Floppy has data. Overwrite data?", 0))
goto get_another;
pb.volumeParam.ioCompletion = (ProcPtr)0;
pb.volumeParam.ioNamePtr = NULL;
pb.volumeParam.ioVRefNum = hpb.volumeParam.ioVRefNum;
myerr = PBUnmountVol(&pb);
/* Feedback("UNMOUNT returns %d ", myerr); */
if (myerr != noErr)
message_note("Error #%d UNmounting floppy volume.", myerr);
else
vref_to_unmount = 0;
DoYield();
DoYield();
mydialog = GetNewDialog(4008, NULL, (WindowPtr)-1);
if (mydialog != NULL) {
SetPort(mydialog);
DrawDialog(mydialog);
}
sprintf(vol_genname, "%.20s #%d", vol_prefix, vol_count);
c2pstr(vol_genname);
myerr = DIZero(curr_drive_number, vol_genname);
/* Feedback("DIZERO returns %d ", myerr); */
if (mydialog != NULL)
DisposDialog(mydialog);
if (myerr != noErr) {
message_alert("Floppy erase failed. Error #%d.", myerr);
goto get_another;
}
DoYield();
DoYield();
}
if (myerr != noErr && myerr != volOnLinErr) {
message_alert("Error #%d mounting floppy volume.", myerr);
goto get_another;
}
else {
result = 1;
vol_count++;
}
}
}
else {
message_alert("Error #%d mounting floppy volume.", myerr);
goto get_another;
}
clear_notify_q(NOTIFY_NEED_DISK);
return result;
}
do_floppy_copy(from_path, partial_path, from_vref, from_dirid)
char *from_path;
char *partial_path;
int from_vref;
long from_dirid;
{
short done, index, myresult, floppy_vref, myerr, stk, need_floppy;
long new_dirid, bytes_needed, blks_needed;
CInfoPBRec cpb;
ParamBlockRec pb;
HParamBlockRec hpb;
HParamBlockRec vpb;
char *ptr1, *ptr2;
char myname[48],
thisfolder[48],
tmpname[48],
sub_folder_name[256];
DoYield();
/*Feedback("DoFloppyCopy: from '%s' part '%s' fvref %d fdir %ld tvref %d tdir %ld ",
** from_path, partial_path, from_vref, from_dirid, to_vref, to_dirid);
*/
cpb.hFileInfo.ioCompletion = 0; /* Synchronous */
cpb.hFileInfo.ioNamePtr = thisfolder; thisfolder[0] = 0;
cpb.hFileInfo.ioVRefNum = from_vref; /* Returned here */
cpb.hFileInfo.ioFDirIndex = -1; /* Get the directory in ioDirID */
cpb.hFileInfo.ioDirID = from_dirid; /* same offset as ioFlNum */
myresult = PBGetCatInfo(&cpb, (Boolean)0); /* Synchronous */
/* Feedback("DoFloppyCopy: result %d FolderName <%.*s> ",
** myresult, thisfolder[0], &thisfolder[1]);
*/
hpb.fileParam.ioCompletion = 0;
hpb.fileParam.ioNamePtr = thisfolder;
hpb.fileParam.ioVRefNum = to_vref;
hpb.fileParam.ioDirID = to_dirid;
myresult = PBDirCreate(&hpb, (Boolean)0);
if (myresult != noErr && myresult != dupFNErr) {
p2cstr(thisfolder);
message_alert("Error #%d creating '%s' directory.", myresult, thisfolder);
return FAILURE;
}
else {
new_dirid = hpb.fileParam.ioDirID;
PUSH_DIR(new_dirid);
cpb.hFileInfo.ioCompletion = 0; /* Synchronous */
cpb.hFileInfo.ioNamePtr = myname; myname[0] = 0;
cpb.hFileInfo.ioFDirIndex = -1; /* Get the directory in ioDirID */
cpb.hFileInfo.ioVRefNum = from_vref; /* Returned here */
cpb.hFileInfo.ioDirID = from_dirid; /* same offset as ioFlNum */
myresult = PBGetCatInfo(&cpb, (Boolean)0); /* Synchronous */
/* Feedback("FLDR: PBGETCatInfo(%d)=%d", from_dirid, myresult); */
if (myresult == noErr) {
PUSH_DIR_INFO(cpb);
cpb.hFileInfo.ioFDirIndex = -1; /* Set the directory in ioDirID */
cpb.hFileInfo.ioNamePtr = NULL;
cpb.hFileInfo.ioVRefNum = to_vref;
cpb.hFileInfo.ioDirID = new_dirid; /* same offset as ioFlNum */
myresult = PBSetCatInfo(&cpb, (Boolean)0); /* Synchronous */
/* Feedback("FLDR: PBSETCatInfo(%d)=%d", hpb.fileParam.ioDirID, myresult); */
}
}
need_floppy = 0;
cancel_current_op = 0;
for (index=1, done=false ; ! done && ! cancel_current_op ; index++) {
if (CheckCmdPeriod())
return CANCEL;
DoYield();
/*
**
** GET INFO
**
*/
vpb.volumeParam.ioCompletion = 0;
vpb.volumeParam.ioNamePtr = NULL;
vpb.volumeParam.ioVRefNum = to_vref;
vpb.volumeParam.ioVolIndex = 0;
myresult = PBHGetVInfo(&vpb, (Boolean)0);
if (myresult != noErr) {
Feedback("DoFloppyCopy: PBHGetVInfo()=%d ", myresult);
message_alert("DoFloppyCopy: PBHGetVInfo()=%d ", myresult);
return FAILURE;
}
/*
**
** COMPUTE NEEDED SIZE
**
*/
cpb.hFileInfo.ioCompletion = 0; /* Synchronous */
cpb.hFileInfo.ioNamePtr = myname; myname[0] = 0;
cpb.hFileInfo.ioVRefNum = from_vref; /* Returned here */
cpb.hFileInfo.ioFDirIndex = index; /* Get the ith file/directory */
cpb.hFileInfo.ioDirID = from_dirid; /* same offset as ioFlNum */
myresult = PBGetCatInfo(&cpb, (Boolean)false); /* Synchronous */
if (cpb.hFileInfo.ioResult == fnfErr)
{
return SUCCESS;
}
if (cpb.hFileInfo.ioResult != noErr)
{
/* This is an ERROR. */
p2cstr(myname);
Feedback("Error #%d PBGetCatInfo(%d)", cpb.hFileInfo.ioResult, index);
return FAILURE;
}
else if ((cpb.hFileInfo.ioFlAttrib & ioDirMask) > 0)
{
/* This is a DIRECTORY. */
blks_needed = 1;
bytes_needed = vpb.volumeParam.ioVAlBlkSiz;
}
else
{
/* This is a FILE. */
hpb.fileParam.ioCompletion = 0;
hpb.fileParam.ioFDirIndex = 0;
hpb.fileParam.ioNamePtr = myname;
hpb.fileParam.ioVRefNum = from_vref;
hpb.fileParam.ioDirID = from_dirid;
hpb.fileParam.ioFVersNum = 0;
myerr = PBHGetFInfo(&hpb, (Boolean)0);
if (myerr != noErr) {
Feedback("PBHGetFInfo(%.*s)=%d ", myname[0], &myname[1], myerr);
return FAILURE;
}
else {
bytes_needed = hpb.fileParam.ioFlLgLen + hpb.fileParam.ioFlRLgLen;
blks_needed = (hpb.fileParam.ioFlLgLen + (vpb.volumeParam.ioVAlBlkSiz - 1))
/ vpb.volumeParam.ioVAlBlkSiz;
blks_needed += (hpb.fileParam.ioFlRLgLen + (vpb.volumeParam.ioVAlBlkSiz - 1))
/ vpb.volumeParam.ioVAlBlkSiz;
blks_needed += 2; /* This sometimes catches small catalog/extent increases... */
} /* Got file info... */
} /* got a file... */
DoYield();
/* Feedback("NEED: Bytes %ld Blks %ld FREE %ld Sz %ld ",
** bytes_needed, blks_needed,
** vpb.volumeParam.ioVFrBlk, vpb.volumeParam.ioVAlBlkSiz);
*/
/*
**
** CHECK NEEDED SPACE
**
*/
if (need_floppy || blks_needed > vpb.volumeParam.ioVFrBlk) {
/* Need new floppy!!!! */
/* Feedback("NEED: NOT ENOUGH Get floppy. "); */
pb.volumeParam.ioCompletion = (ProcPtr)0;
pb.volumeParam.ioNamePtr = NULL;
pb.volumeParam.ioVRefNum = to_vref;
myerr = PBUnmountVol(&pb);
/* Feedback("NEED: UnMount = %d. ", myerr); */
if (! GetFloppy(&floppy_vref))
{
return CANCEL;
}
to_vref = floppy_vref;
new_dirid = 2;
need_floppy = 0;
vref_to_unmount = to_vref;
/* Feedback("NEED: CREATING PATH <%s>. ", partial_path); */
for (stk=0, ptr1 = partial_path ; *ptr1 != '\0' ; ) {
if (*ptr1 == ':')
ptr1++;
for (ptr2 = tmpname; *ptr1 != '\0' && *ptr1 != ':' ; )
*ptr2++ = *ptr1++;
if (*ptr1 == ':')
ptr1++;
*ptr2 = '\0';
if (tmpname[0] != '\0') {
c2pstr(tmpname);
hpb.fileParam.ioCompletion = 0;
hpb.fileParam.ioNamePtr = tmpname;
hpb.fileParam.ioVRefNum = to_vref;
hpb.fileParam.ioDirID = new_dirid;
myresult = PBDirCreate(&hpb, (Boolean)0);
if (myresult != noErr) {
p2cstr(tmpname);
Feedback("Error #%d Floppy CreateDir(%s)", myresult, tmpname);
message_note("Error #%d Floppy CreateDir(%s)", myresult, tmpname);
return FAILURE;
}
else {
new_dirid = hpb.fileParam.ioDirID;
/* Feedback("NEED: CREATED FOLDER <%.*s> ID %ld. ",
** tmpname[0], &tmpname[1], new_dirid);
*/
if (stk < dir_info_stk_ptr) {
dir_info_stk[stk].hFileInfo.ioFDirIndex = -1; /* Set the directory in ioDirID */
dir_info_stk[stk].hFileInfo.ioNamePtr = NULL;
dir_info_stk[stk].hFileInfo.ioVRefNum = to_vref;
dir_info_stk[stk].hFileInfo.ioDirID = new_dirid; /* same offset as ioFlNum */
myresult = PBSetCatInfo(&dir_info_stk[stk], (Boolean)0); /* Synchronous */
if (myresult != noErr)
Feedback("NEED: Error #%d PBSetCatinfo(%.*s, %ld). ",
myresult, tmpname[0], &tmpname[1], new_dirid);
}
dir_stk[stk++] = new_dirid;
}
} /* tmpname has characters, create dir... */
} /* for walk of partial path to create directories */
hpb.fileParam.ioCompletion = 0;
hpb.fileParam.ioNamePtr = thisfolder;
hpb.fileParam.ioVRefNum = to_vref;
hpb.fileParam.ioDirID = new_dirid;
myresult = PBDirCreate(&hpb, (Boolean)0);
if (myresult != noErr) {
p2cstr(thisfolder);
Feedback("Error #%d Floppy CreateDir(%s)", myresult, thisfolder);
message_note("Error #%d Floppy CreateDir(%s)", myresult, thisfolder);
return FAILURE;
}
else {
new_dirid = hpb.fileParam.ioDirID;
/* Feedback("NEED: CREATED FOLDER <%.*s> ID %ld. ",
** thisfolder[0], &thisfolder[1], new_dirid);
*/
if (stk < dir_info_stk_ptr) {
dir_info_stk[stk].hFileInfo.ioFDirIndex = -1; /* Set the directory in ioDirID */
dir_info_stk[stk].hFileInfo.ioNamePtr = NULL;
dir_info_stk[stk].hFileInfo.ioVRefNum = to_vref;
dir_info_stk[stk].hFileInfo.ioDirID = new_dirid; /* same offset as ioFlNum */
myresult = PBSetCatInfo(&dir_info_stk[stk], (Boolean)0); /* Synchronous */
if (myresult != noErr)
Feedback("NEED: Error #%d PBSetCatinfo(%.*s, %ld). ",
myresult, thisfolder[0], &thisfolder[1], new_dirid);
}
dir_stk[stk++] = new_dirid;
}
/* Feedback("NEED: CREATED PATH <%s> todir %ld. ", partial_path, new_dirid);
** Feedback("NEED: stk = %d dir_stk_ptr = %d dir_info_stk_ptr = %d ",
** stk, dir_stk_ptr, dir_info_stk_ptr);
*/
} /* Not enough blocks for file... */
/*
**
** PROCESS OBJECT
**
*/
if ((cpb.hFileInfo.ioFlAttrib & ioDirMask) > 0)
{
/* This is a DIRECTORY. */
/* Feedback("DIR: PARTIAL <%s> THIS <%.*s>. ",
** partial_path, thisfolder[0], &thisfolder[1]);
*/
sprintf(sub_folder_name, "%s%s%.*s", partial_path,
( (partial_path[strlen(partial_path)-1] == ':') ? "" : ":" ),
thisfolder[0], &thisfolder[1]);
UpdateProgress(++current_count);
to_dirid = new_dirid;
myresult = do_floppy_copy(from_path, sub_folder_name,
from_vref, cpb.hFileInfo.ioDirID);
to_dirid = CURRENT_DIR();
switch (myresult) {
/*case FAILURE:*/
case CANCEL:
return myresult;
break;
}
/* Feedback("DIR: RETURNED THIS <%.*s>. ", thisfolder[0], &thisfolder[1]); */
}
else
{
/* This is a FILE. */
/* Feedback("COPY FILE '%.*s' fv %d fd %ld tv %d td %ld ",
** myname[0], &myname[1], from_vref, from_dirid,
** to_vref, hpb.fileParam.ioDirID);
*/
Feedback("Copying '%.*s'...", myname[0], &myname[1]);
myresult = CopyFile(myname, from_vref, from_dirid, to_vref, new_dirid);
UpdateProgress(++current_count);
if (myresult != noErr) {
if (myresult == dirFulErr || myresult == dskFulErr) {
need_floppy = 1;
index--; /* Do this one again... */
}
else {
message_alert("Error #%d copying file '%.*s'.",
myresult, myname[0], &myname[1]);
return FAILURE;
}
}
} /* got a file... */
/*
**
** END OF MAJOR LOOP
**
*/
} /* for file in directory... */
return SUCCESS;
}
#define my_disk_item 69
file_count(from_vref, from_dirid)
int from_vref;
long from_dirid;
{
short done, index, myresult;
int count = 0;
CInfoPBRec cpb;
char myname[48];
char thisfolder[48];
extern void SProgressCounting();
DoYield();
/*Feedback("DoFloppyCopy: from '%s' part '%s' fvref %d fdir %ld tvref %d tdir %ld ",
** from_path, partial_path, from_vref, from_dirid, to_vref, to_dirid);
*/
cpb.hFileInfo.ioCompletion = 0; /* Synchronous */
cpb.hFileInfo.ioNamePtr = thisfolder; thisfolder[0] = 0;
cpb.hFileInfo.ioVRefNum = from_vref; /* Returned here */
cpb.hFileInfo.ioFDirIndex = -1; /* Get the directory in ioDirID */
cpb.hFileInfo.ioDirID = from_dirid; /* same offset as ioFlNum */
myresult = PBGetCatInfo(&cpb, (Boolean)0); /* Synchronous */
for (index=1, done=false ; ! done && ! cancel_current_op ; index++) {
if (CheckCmdPeriod()) {
return CANCEL;
}
DoYield();
cpb.hFileInfo.ioCompletion = 0; /* Synchronous */
cpb.hFileInfo.ioNamePtr = myname; myname[0] = 0;
cpb.hFileInfo.ioVRefNum = from_vref; /* Returned here */
cpb.hFileInfo.ioFDirIndex = index; /* Get the ith file/directory */
cpb.hFileInfo.ioDirID = from_dirid; /* same offset as ioFlNum */
myresult = PBGetCatInfo(&cpb, (Boolean)false); /* Synchronous */
if (cpb.hFileInfo.ioResult != noErr)
{
/* This is an ERROR. */
if (cpb.hFileInfo.ioResult != fnfErr) {
Feedback("Error #%d PBGetCatInfo(%d)", cpb.hFileInfo.ioResult, index);
return FAILURE;
}
else
done = 1;
}
else if ((cpb.hFileInfo.ioFlAttrib & ioDirMask) > 0)
{
/* This is a DIRECTORY. */
UpdateProgress(++file_count_count);
count += file_count(from_vref, cpb.hFileInfo.ioDirID) + 1;
}
else
{
/* This is a FILE. */
if ((++file_count_count & 8) != 0)
UpdateProgress(file_count_count);
count++;
} /* got a file... */
} /* for file in directory... */
return count;
}
#define my_disk_item 69
pascal Boolean DiskFilter(mydialog, myevent, itemhit)
DialogPtr mydialog;
EventRecord *myevent;
short *itemhit;
{
#pragma unused (mydialog)
int myascii;
EventRecord local_event;
if (myevent->what == keyDown) {
myascii = myevent->message & 255;
if (myascii == '\015' || myascii == '\003') {
*itemhit = ((DialogRecord *) mydialog)->aDefItem;
return true;
}
else if (myascii == 0x1B) {
*itemhit = ((DialogRecord *) mydialog)->aDefItem;
return true;
}
}
else if (GetOSEvent(diskMask, &local_event)) {
if (local_event.what == diskEvt) {
curr_drive_number = local_event.message & 0x00007FFF;
*itemhit = my_disk_item;
return true;
}
else
return false;
}
else
return false;
}
#define d_get_floppy_id 4004
#define d_floppy_prompt_item 2
SFGetFloppy(prompt)
char *prompt;
{
GrafPtr saveport;
DialogPtr mydialog;
short itemhit, done;
int status;
pascal Boolean DiskFilter();
GetPort(&saveport);
mydialog = GetNewDialog(d_get_floppy_id, NULL, (WindowPtr)-1);
MySetText(mydialog, d_floppy_prompt_item, prompt);
for (done=false; ! done; ) {
SetPort(mydialog);
FrameButton(mydialog, 1);
ModalDialog(DiskFilter, &itemhit);
if (itemhit == my_disk_item) {
done = true; status = 1;
}
else if (itemhit == ok) { /* *Really* Cancel. */
done = true; status = 0;
}
}
DisposDialog(mydialog);
SetPort(saveport);
return status;
}
SFEject(drive)
int drive;
{
IOParam pb;
pb.ioCompletion = (ProcPtr)0; /* */
pb.ioNamePtr = NULL; /* */
pb.ioVRefNum = drive; /* ioVRefNum ≈ ioDrvNum. 1 = internal drive */
PBEject((ParmBlkPtr)&pb);
if (pb.ioResult != noErr && pb.ioResult != nsDrvErr) {
Feedback("Error #%d trying to eject floppy in drive #%d.\n",
pb.ioResult, drive);
/* message_alert("Error #%d trying to eject floppy in drive #%d.\n",
pb.ioResult, drive); */
}
}
CopyFile(name, from_vref, from_dirid, to_vref, to_dirid)
char *name; /* Pascal */
int from_vref;
long from_dirid;
int to_vref;
long to_dirid;
{
short ferr, terr, myerr;
int result = noErr;
HParamBlockRec fparm, tparm;
SetVol(NULL, from_vref);
fparm.ioParam.ioCompletion = 0;
fparm.ioParam.ioNamePtr = name;
fparm.ioParam.ioVRefNum = from_vref;
fparm.ioParam.ioVersNum = 0;
fparm.ioParam.ioPermssn = fsRdPerm;
fparm.ioParam.ioMisc = NULL;
fparm.fileParam.ioDirID = from_dirid;
ferr = PBHOpen(&fparm, false);
if (ferr != noErr) {
Feedback("Error #%d opening FROM DATA '%.*s'", ferr, name[0], &name[1]);
message_alert("Error #%d opening FROM DATA '%.*s'", ferr, name[0], &name[1]);
result = ferr;
}
else if (! cancel_current_op) {
SetVol(NULL, to_vref);
tparm.ioParam.ioCompletion = 0;
tparm.ioParam.ioNamePtr = name;
tparm.ioParam.ioVRefNum = to_vref;
tparm.ioParam.ioVersNum = 0;
tparm.ioParam.ioPermssn = fsWrPerm;
tparm.ioParam.ioMisc = NULL;
tparm.fileParam.ioDirID = to_dirid;
terr = PBHCreate(&tparm, false);
if (terr != noErr && terr != dupFNErr) {
Feedback("Error #%d creating TO DATA '%.*s'", terr, name[0], &name[1]);
message_alert("Error #%d creating TO DATA '%.*s'", terr, name[0], &name[1]);
result = terr;
}
else {
terr = PBHOpen(&tparm, false);
if (terr != noErr) {
Feedback("Error #%d opening TO DATA '%.*s'", terr, name[0], &name[1]);
message_alert("Error #%d opening TO DATA '%.*s'", terr, name[0], &name[1]);
result = terr;
}
else {
if ((myerr=Copy(&fparm, &tparm)) != noErr) {
Feedback("Error #%d COPYING DATA '%.*s'", myerr, name[0], &name[1]);
message_alert("Error #%d COPYING DATA '%.*s'", myerr, name[0], &name[1]);
}
else {
myerr = PBGetEOF((ParmBlkPtr)&fparm, false);
if (myerr == noErr) {
tparm.ioParam.ioMisc = fparm.ioParam.ioMisc;
myerr = PBSetEOF((ParmBlkPtr)&tparm, false);
if (myerr != noErr) {
Feedback("Error #%d setting EOF DATA '%.*s'", myerr, name[0], &name[1]);
message_alert("Error #%d setting EOF DATA '%.*s'", myerr, name[0], &name[1]);
result = myerr;
}
}
else {
Feedback("Error #%d getting EOF DATA '%.*s'", myerr, name[0], &name[1]);
message_alert("Error #%d getting EOF DATA '%.*s'", myerr, name[0], &name[1]);
result = myerr;
}
}
PBClose((ParmBlkPtr)&tparm, false);
}
PBClose((ParmBlkPtr)&fparm, false);
if (result == noErr && ! cancel_current_op) {
SetVol(NULL, from_vref);
fparm.ioParam.ioCompletion = 0;
fparm.ioParam.ioNamePtr = name;
fparm.ioParam.ioVRefNum = from_vref;
fparm.ioParam.ioVersNum = 0;
fparm.ioParam.ioPermssn = fsRdPerm;
fparm.ioParam.ioMisc = NULL;
fparm.fileParam.ioDirID = from_dirid;
ferr = PBHOpenRF(&fparm, false);
if (ferr != noErr) {
Feedback("Error #%d opening FROM RSRC '%.*s'", ferr, name[0], &name[1]);
message_alert("Error #%d opening FROM RSRC '%.*s'", ferr, name[0], &name[1]);
result = ferr;
}
else {
SetVol(NULL, to_vref);
tparm.ioParam.ioCompletion = 0;
tparm.ioParam.ioNamePtr = name;
tparm.ioParam.ioVRefNum = to_vref;
tparm.ioParam.ioVersNum = 0;
tparm.ioParam.ioPermssn = fsWrPerm;
tparm.ioParam.ioMisc = NULL;
tparm.fileParam.ioDirID = to_dirid;
terr = PBHOpenRF(&tparm, false);
if (terr != noErr) {
Feedback("Error #%d opening TO RSRC '%.*s'", terr, name[0], &name[1]);
message_alert("Error #%d opening TO RSRC '%.*s'", terr, name[0], &name[1]);
result = terr;
}
else if (! cancel_current_op) {
if ((myerr=Copy(&fparm, &tparm)) != noErr) {
Feedback("Error #%d COPYING RSRC '%.*s'", myerr, name[0], &name[1]);
message_alert("Error #%d COPYING RSRC '%.*s'", myerr, name[0], &name[1]);
result = myerr;
}
else {
myerr = PBGetEOF((ParmBlkPtr)&fparm, false);
if (myerr == noErr) {
tparm.ioParam.ioMisc = fparm.ioParam.ioMisc;
myerr = PBSetEOF((ParmBlkPtr)&tparm, false);
if (myerr != noErr) {
Feedback("Error #%d setting EOF RSRC '%.*s'", myerr, name[0], &name[1]);
message_alert("Error #%d setting EOF RSRC '%.*s'", myerr, name[0], &name[1]);
result = myerr;
}
}
else {
Feedback("Error #%d getting EOF RSRC '%.*s'", myerr, name[0], &name[1]);
message_alert("Error #%d getting EOF RSRC '%.*s'", myerr, name[0], &name[1]);
result = myerr;
}
}
PBClose((ParmBlkPtr)&tparm, false);
}
PBClose((ParmBlkPtr)&fparm, false);
}
} /* if (result == noErr) */
if (result == noErr && ! cancel_current_op) {
SetVol(NULL, from_vref);
fparm.ioParam.ioCompletion = 0;
fparm.fileParam.ioFDirIndex = 0;
fparm.ioParam.ioNamePtr = name;
fparm.ioParam.ioVRefNum = from_vref;
fparm.fileParam.ioDirID = from_dirid;
fparm.ioParam.ioVersNum = 0;
myerr = PBHGetFInfo(&fparm, false);
if (myerr != noErr) {
Feedback("Error #%d Getting File info '%.*s'",
myerr, name[0], &name[1]);
}
else {
fparm.ioParam.ioVRefNum = to_vref;
fparm.fileParam.ioDirID = to_dirid;
SetVol(NULL, to_vref);
myerr = PBHSetFInfo(&fparm, false);
if (myerr != noErr)
Feedback("Error #%d Setting File info '%.*s'",
myerr, name[0], &name[1]);
}
} /* if (result == noErr) */
} /* else PBHCreate(to) succeeded... */
} /* else PBHOpen(from) succeeded... */
FlushVol(NULL, to_vref);
return result;
}
#define INPARAM inparm->ioParam
#define OUTPARAM outparm->ioParam
Copy(inparm, outparm)
HParamBlockRec *inparm;
HParamBlockRec *outparm;
{
short done, myerr;
char mybuffer[512];
for (done=false; ! done && ! cancel_current_op ; ) {
DoYield();
INPARAM.ioReqCount = (long)512;
INPARAM.ioBuffer = mybuffer;
INPARAM.ioPosMode = fsAtMark;
myerr = PBRead((ParmBlkPtr)inparm, (Boolean)false);
if (myerr != noErr && myerr != eofErr)
return myerr;
if (myerr == eofErr)
done = true;
DoYield();
OUTPARAM.ioReqCount = INPARAM.ioActCount;
OUTPARAM.ioBuffer = mybuffer;
OUTPARAM.ioPosMode = fsAtMark;
myerr = PBWrite((ParmBlkPtr)outparm, (Boolean)false);
if (myerr != noErr)
return myerr;
if (INPARAM.ioActCount != OUTPARAM.ioActCount) {
Feedback("Error, output does not match size of input [%d : %d].",
INPARAM.ioActCount, OUTPARAM.ioActCount);
message_alert("Error, output does not match size of input [%d : %d].",
INPARAM.ioActCount, OUTPARAM.ioActCount);
done = true;
}
}
return noErr;
}